﻿using Acme.BookStore.Dishes;
using Microsoft.AspNetCore.Mvc;
using SC.UserCenter.Infra;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace Acme.BookStore.DishesGroupings
{
    /// <summary>
    /// 实现菜品分组接口
    /// </summary>
    [ApiExplorerSettings(GroupName = "v2")]
    public class DishesGroupingServices : ApplicationService, IDishesGroupingServices
    {
        /// <summary>
        ///注入
        /// </summary>
        private readonly IRepository<DishesGrouping> repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repository"></param>
        public DishesGroupingServices(IRepository<DishesGrouping> repository)
        {
            this.repository = repository;
        }
        /// <summary>
        ///添加菜品分组
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost("PostDishesGrouping")]
        public async Task<ApiResult> PostDishesGrouping(DishesGroupingDTO dto)
        {
            try
            {
                try
                {
                    var list = ObjectMapper.Map<DishesGroupingDTO, DishesGrouping>(dto);
                    await repository.InsertAsync(list);
                    return ApiResult.Ok(data: list);
                }
                catch (Exception ex)
                {
                    ex.HelpLink = "操作失败";
                    return ApiResult.Fail(msg: ex.Message);
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 菜品分组绑定
        /// </summary>
        /// <returns></returns>
        [HttpGet("PostDishesGrouBing")]
        public async Task<ApiResult> PostDishesGrouBing()
        {
             var list= await repository.GetListAsync();
              return ApiResult.Ok(list);
        }

    }
}
